public class Stack<base>
{	
	private class Node
	{
		private base data;
		private Node next;
		private Node()
		{
			data = null;
			next = null;
		}
	}
	
	private Node head;
	
	public Stack()
	{
		head = null;
	}

	public void pop()
	{
		if (isEmpty()) {System.out.println("Stack is empty!");}
		else 
		{
			head = head.next;
		}
	}

	public base pop2()
	{
		if (isEmpty()) {System.out.println("Stack is empty!"); return null;}
		else 
		{
			base r = head.data;
			head = head.next;
			return r;
		}
	}

	public void push(base x)
	{
		Node p = head;
		head = new Node();
		if (!isEmpty())
		{
			head.data = x;
			head.next = p;
		}
		else {System.out.println("Memory is not enough!");}
	}
	
	public boolean isEmpty()
	{
		return head == null;
	}

	public void clear()
	{
		head = null;
	}
}
